<template>
  <InnerPageTable ref="listTable" :config="pageTableConfig">
  </InnerPageTable>
</template>

<script>

import { superviseInfoAPI } from "@api/superviseInfo";

export default {
  name: "enclosureList",
  props: ['list'],
  data() {
    return {
      pageTableConfig: {
        loadDataFn: this.getTableList,
        columns: [
          {
            title: '序号',
            key: 'index',
            width: 100,
            render: (h, { row, index}) => {
              return h("RowTools", {
                props: {
                  data: [
                    {
                      type: 'text',
                      text: index + 1,
                    },
                  ]
                }
              });
            }
          },
          {
            title: '附件名称',
            key: 'fileNameCopy'
          },
          {
            title: '操作',
            width: 80,
            render: (h, { row }) => {
              return h("RowTools", {
                props: {
                  data: [
                    {
                      type: 'icon',
                      icon: 'md-download',
                      text: '查看',
                      handle: () => this.downloadHandle(row)
                    },
                  ]
                }
              });
            }
          }
        ],
        initParam: {
          id: this.id
        },
        isPage: false,
        autoFirst: true,
      }
    }
  },
  mounted() {
    this.$emit('SetTitle', '附件列表')
  },
  methods: {
    getTableList({ responseProcess }) {
      const listCopy = this.list.map(item => {
        const index = item.fileName.indexOf('@')
        if (index > -1) {
          item.fileNameCopy = item.fileName.slice(index + 1)
        } else {
          item.fileNameCopy = item.fileName
        }
        return item
      })
      const data = { records: listCopy }
      responseProcess(data)
    },
    downloadHandle(row) {
      superviseInfoAPI.getFileUrl({ fileKey: row.fileName }).then(res => {
        window.open(res.data)
      })
    }
  }
};
</script>

<style scoped>

</style>
